#!/bin/sh
# -*- coding: utf-8; tab-width: 4 -*-
# vim: ts=4 noet ai

# Part of ClickGuard
# Copyright © 2016  Desktopd Project
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Written for Zombie Navigator
# Copyright © 2016  Zombie Navigator Developers


dir="`dirname "$0"`"/..
cd "$dir"


printf "\n"

[ "$1" ] && {
	find src/ -name '*.js' -exec sh -c \
		"printf '%s: \n' "'"$1"'" ; grep 'require\s*(' "'"$1"'" | grep -v '^\s*//' | sed 's/^.*require\s*(\([^)]*\)).*$/\1/' | sort | uniq | grep --color -- "'"$2"'" && printf '\n'" -- {} "$1" \;
:;} || {
	find src/ -name '*.js' -exec sh -c \
		"printf '%s: \n\n' "'"$1"'" ; grep 'require\s*(' "'"$1"'" | grep -v '^\s*//' | sed 's/^.*require\s*(\([^)]*\)).*$/\1/' | sort | uniq" -- {} \;
}

